//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "common\fn_actionSetLocal.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_action","_key","_value","_result","_actions","_id","_index","_local_action"];
DEFAULT_PARAM(_object,0,objNull);
DEFAULT_PARAM(_action,1,[]);
DEFAULT_PARAM(_key,2,"");
DEFAULT_PARAM(_value,3,nil);
_actions = [];
_actions = OGETVAR(_object,QGVAR(LOCAL_MISSION_ACTIONS),_actions);
TRACE_1("LocalMissionActions",_actions);
_id = [_action, TMF_HK_ACTION_ID,-1,THIS_FILE] call FFUNC(hashGet);
_index = -1;
if (_id >= 0 && count _actions > 0) then {
	for "_i" from 0 to ((count _actions) - 1) step 1 do {
		if (_id == ([(_actions select _i), TMF_HK_ACTION_ID,-1,THIS_FILE] call FFUNC(HashGet))) exitWith {_index = _i};
	};
};
TRACE_2("Found index",_index,(count _actions));
if (_index >= 0) then {
	_local_action = (_actions select _index);
} else {
	_index = count _actions;
	_local_action = (call FFUNC(hashEmpty));
	_local_action = [_local_action, TMF_HK_ACTION_ID,_id] call FFUNC(HashSet);
};
_local_action = [_local_action, _key,_value] call FFUNC(HashSet);
_actions set [_index, _local_action];
OSETVAR(_object,QGVAR(LOCAL_MISSION_ACTIONS),_actions);

TRACE("End",_actions);
TMFPROFILERSTOP;